const baidu = require("./baidu.js");

const transText =
  (api = baidu) =>
  async (req, res) => {
    // req.body post 数据;
    // req.query get（地址栏）数据
    // req.params 路由（如/:id）数据
    const $string = req.body.string || "";
    const $lang = req.body.lang || "en";
    if ($lang === "en" || $string == "") {
      return res.status(201).json({ err: "string is empty" });
    }
    const result = await api($string, $lang);
    return res.status(200).json(result);
  };

module.exports = transText;
